<template>
	<div>
		<el-breadcrumb separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>权限管理</el-breadcrumb-item>
			<el-breadcrumb-item>权限列表</el-breadcrumb-item>
		</el-breadcrumb>
		<el-card>
			<el-table :data="powerList" border stripe style="width: 100%">
				<el-table-column type="index" label="序号">
				</el-table-column>
				<el-table-column prop="authName" label="权限名称">
				</el-table-column>
				<el-table-column prop="path" label="路径">
				</el-table-column>
				<el-table-column prop="level" label="权限等级">
					<template slot-scope = "scope">
						<el-tag type="success" v-if="scope.row.level == '0'">一级</el-tag>
						<el-tag type="warning" v-else-if="scope.row.level == '1'">二级</el-tag>
						<el-tag type="danger" v-else>三级</el-tag>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pageInfo.pagenum" :page-sizes="[5,8]" :page-size="pageInfo.pagesize"
				layout="total, sizes, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</el-card>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				powerList: [],
				pageInfo: {
					pagenum: 1,
					pagesize: 5
				},
				total: ''
			}
		},
		methods: {
			async getPermByPage() {
				let {
					data: res
				} = await this.$http.get('/permission/rights/list', {
					params: this.pageInfo
				})
				
				this.powerList = res.data.perms;
				this.total = res.data.total;
				this.pageInfo.pagenum = res.data.pagenum
			},
			handleSizeChange(newSize) {
				this.pageInfo.pagesize = newSize;
				this.getPermByPage()
			},
			handleCurrentChange(newpage) {
				this.pageInfo.pagenum = newpage;
				this.getPermByPage()
			}
		},
		created() {
			this.getPermByPage();
		}
	}
</script>

<style>
</style>
